import goodsApi from '../api/shopGoods'
export default {
    //命名空间
    namespaced: true,
   
    state: {
        isUpdata:false,
        curPage: 1,
        eachPage: 3,
        total: 0,
        maxPage: 0,
        rows: [],
       
    },
    getters: {
        text() { }
    },
    mutations: {

        updataGoods(state,goods) {
            Object.assign(state, goods)
        },

      async delteGoods(state,{_id,images}){
          console.log(_id,images);
       const data = await goodsApi.delGoods(_id)
       //删除资源服务器图片
    //    await goodsApi.delImg(_id,images)
       Object.assign(state, data)
       },

       setCurPage(state, curPage) {
         
        state.curPage = curPage;
       
      },
      //修改图片
     async updataImgGoods(state,{_id,images}){
       const data =await goodsApi.updataImg({_id,images})
    Object.assign(state,data)
      },
     async serchDoods(state,serName){
      const data = await goodsApi.serchGoods(serName)
      state.rows = data
      
      }
    },
    actions: {
        //携带一个 context 的参数可解构
        async get({ state, commit }) {
            const { curPage, eachPage } = state
            const data = await goodsApi.get({curPage, eachPage})
          
            commit("updataGoods", data)
        },
     
    }

};